
import { _decorator, Node, Prefab } from 'cc';
import { UITransform } from 'cc';
import { BaseView } from '../../../../scripts/libs/rxjs/cc3/BaseView';
import { BindDragWithLimited } from '../../../../scripts/libs/rxjs/cc3/BindNode';
import { lm } from '../../LobbyManager';
import { EditorStageView } from './EditorStageView';
import { EditorInspectorNumber } from './EditorInspectorNumber';
import { EditorInspectorString } from './EditorInspectorString';
const { ccclass, property } = _decorator;

@ccclass('EditorStageInspector')
export class EditorStageInspector extends BaseView {

    editorStageView: EditorStageView = null;

    @property(EditorInspectorNumber)
    stageNumInspectorNumber: EditorInspectorNumber = null;

    @property(EditorInspectorNumber)
    timeInspectorNumber: EditorInspectorNumber = null;

    @property(EditorInspectorNumber)
    hardInspectorNumber: EditorInspectorNumber = null;

    @property(EditorInspectorString)
    tipInspectorString: EditorInspectorString = null;

    willBind(): void {
        this.refresh();
    }

    useObserves() {
        return [
            this.stageNumInspectorNumber.changedCommand.subscribe(_ => this.editorStageView.remakeStageInfo()),
            this.timeInspectorNumber.changedCommand.subscribe(_ => this.editorStageView.remakeStageInfo()),
            this.hardInspectorNumber.changedCommand.subscribe(_ => this.editorStageView.remakeStageInfo()),
            this.tipInspectorString.changedCommand.subscribe(_ => this.editorStageView.remakeStageInfo()),
        ]
    }

    start() {
        BindDragWithLimited(this.node, lm.uiRoot.camera, () => {
            let size = this.node.parent.getComponent(UITransform).contentSize;
            return { x: [-size.width / 2, size.width / 2], y: [-size.height / 2, size.height / 2] }
        }).subscribe(_ => {
            if (_.type == 'touch-start') {
                this.node.setSiblingIndex(-1);
            }
        }).addTo(this.node);
    }

    refresh() {
        this.stageNumInspectorNumber.setGetRP(() => this.editorStageView.stageNum);
        this.timeInspectorNumber.setGetRP(() => this.editorStageView.time);
        this.hardInspectorNumber.setGetRP(() => this.editorStageView.hard);
        this.tipInspectorString.setGetRP(() => this.editorStageView.tip);
    }

}


